#include "gtest/gtest.h"
#include "TransAppender.h"
#include "Topic.h"

TEST(TransAppenderTest, testMain){
    auto tp = std::make_unique<Topic>("stream-trans-appender", ".");
	auto appender = std::make_unique<TransAppender>(*tp);
	appender->open();

	ASSERT_TRUE(appender->transaction()->execute(1, "hello world").commit());
	ASSERT_TRUE(appender->transaction()->execute(2, "hello world").commit());
	ASSERT_TRUE(appender->transaction()->execute(3, "hello world").rollback());

	appender->close();
}

TEST(TransAppenderTest, testChainCall){
    auto tp = std::make_unique<Topic>("stream-trans-appender-chaincall", ".");
	auto appender = std::make_unique<TransAppender>(*tp);
	appender->open();

	ASSERT_TRUE(appender->transaction()->commit());// meta->logSize()->value();
	ASSERT_TRUE(appender->transaction()->rollback()); // meta->logSize()->value()

	ASSERT_TRUE(appender->transaction()->execute(1, "hello world").execute(2, "hello world2").execute(3, "hello world3").commit());
	ASSERT_TRUE(appender->transaction()->execute(1, "hello world").execute(2, "hello world2").execute(3, "hello world3").commit());

	ASSERT_TRUE(appender->transaction()->execute(1, "hello world").execute(2, "hello world2").execute(3, "hello world3").rollback());

	appender->close();
}
